package mo.tags.greedy;

import java.util.Arrays;

public class L945 {

    public int minIncrementForUnique(int[] nums) {
        Arrays.sort(nums);
        int cur = nums[0];
        int n = nums.length;
        int increment = 0;
        for (int i = 1; i < n; i++) {
            if (nums[i] > cur) {
                cur = nums[i];
            } else {
                cur++;
                increment += cur - nums[i];
            }
        }
        return increment;
    }

    public static void main(String[] args) {
        L945 test = new L945();
        System.out.println(test.minIncrementForUnique(new int[]{3,2,1,2,1,7}));
    }

}
